<template>
  <el-dialog title="选择风险点" :close-on-click-modal="false" :visible.sync="visible" class="JNPF-dialog JNPF-dialog_center" lock-scroll append-to-body width="1200px">
    <el-row class="JNPF-common-search-box" :gutter="16">
      <div class="JNPF-common-search-box-right">
        <el-tooltip effect="dark" :content="$t('common.refresh')" placement="top">
          <el-link icon="icon-ym icon-ym-Refresh JNPF-common-head-icon" :underline="false" @click="refresh()" />
        </el-tooltip>
      </div>
    </el-row>
    <JNPF-table ref="multipleTable" v-loading="listLoading" :data="list" hasC @selection-change="handleSelectionChange" :border="false">
      <el-table-column prop="mc" label="名称"/>
      <el-table-column prop="lx" label="类型"  />
      <el-table-column prop="qumc" label="区域名称"  />
      <el-table-column label="排查人" fixed="right" width="150">
          <template slot-scope="scope">
            <el-select v-model="scope.row.pcrId" placeholder="请选择" clearable :style='{"width":"100%"}' filterable>
              <el-option v-for="(item, index) in pcrOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
            </el-select>
          </template>
			</el-table-column>
    </JNPF-table>
    <!-- <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="init" /> -->
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{
        $t("common.cancelButton")
      }}</el-button>
      <el-button type="primary" @click="select()">{{
        $t("common.confirmButton")
      }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import request from '@/utils/request'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
  data() {
    return {
      visible: false,
      listLoading: true,
      keyword: "",
      list: [],
      // total: 0,
      checked: [],
      query: {},
      listQuery: {
					// currentPage: 1,
					// pageSize: 20,
          // sort: "desc",
          // sidx: "",
      },

      rightHeader1: [{label: '排查人',key: 'pcrId'}],
			// rightsDate:[],

			pcrOptions:[],
			pcr:[],


    };
  },
  created(){
    this.getpcrOptions();
    // this.init();
  },
  methods: {
    getpcrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.pcrOptions = res.data
			})
		},
    init(fxdPcrList) {
      this.visible = true;
      this.listLoading = true;
      // if(fxdPcrList.length == 0){
        let query = {
          ...this.listQuery,
          ...this.query
        };
        request({
          url: `/api/System/YHPCXXFXD`,
              method: 'POST',
              data: query
          }).then(res => {
              this.list = res.data;
              this.listLoading = false;
              // this.total = res.data.pagination.total;
              this.$nextTick(() => {
                  this.tableHeight = "100%"
              // if(this.list.length > 0){
                //   for(let i=0;i<this.list.length;i++){
                //     for(let r=0;r<this.checked.length;r++){
                //       if(this.list[i].id == this.checked[r].id){
                //         this.$refs.multipleTable.toggleRowSelection(this.list[i]);
                //       }
                //     }
                //   }
              // }
            });
        })  
      // }else{
        this.checked = fxdPcrList;
        this.listLoading = false;
      // }
    },
    refresh() {
      // this.keyword = "";
      this.init();
    },
    select() {
      if (!this.checked.length) return;
      this.visible = false;
      let checkedList = this.checked;
      let pcrOptionsList = this.pcrOptions;
      for(let i=0;i<checkedList.length;i++){
          for(let r=0;r<pcrOptionsList.length;r++){
             if(checkedList[i].pcrId == pcrOptionsList[r].F_Id){
                checkedList[i].pcrMc = pcrOptionsList[r].F_RealName;
             }
          }
      }
      this.$emit("refreshDataList", this.checked);
    },
    handleSelectionChange(val) {
      this.checked = val;
    },
  },
};
</script>
<style lang="scss" scoped>
>>> .el-dialog__body {
  height: 70vh;
  padding: 0 0 10px !important;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  .JNPF-common-search-box {
    margin-bottom: 0;
    .JNPF-common-search-box-right {
      padding: 10px 10px 0 0;
    }
  }
}
</style>